﻿//
//  Copyright (c) 2008, WebAula S/A 
//  All rights reserved.
//
//  Authors : 
//
//           * Ivan Paulovich (ivan@100loop.com)
//           Blog: http://www.100loop.com/          
//           Messenger: ivanpaulovich@hotmail.com 
//           Twitter: @ivanpaulovich
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Core;
using Core.Domain.Repositories;
using Core.Domain.Model;
using System.IO;

namespace BlogPlugin.Controllers
{
    public class PostController : Controller
    {
        public ActionResult Index()
        {
            IRepository<Post> repo = new PostRepository();
            return View(repo.GetAll());
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Post post)
        {
            IRepository<Post> repo = new PostRepository();
            repo.Save(post);
            return RedirectToAction("Index");
        }

        public ActionResult Edit(int id)
        {
            IRepository<Post> repo = new PostRepository();
            return View(repo.GetById(id));
        }

        [HttpPost]
        public ActionResult Edit(int id, Post post)
        {
            IRepository<Post> repo = new PostRepository();
            repo.Update(post);
            return RedirectToAction("Index");
        }

        public ActionResult View(int id)
        {
            IRepository<Post> repo = new PostRepository();
            return View(repo.GetById(id));
        }

        public ActionResult Delete(int id)
        {
            IRepository<Post> repo = new PostRepository();
            repo.Delete(repo.GetById(id));
            return RedirectToAction("Index");
        }
    }
}
